import requests
from tronapi import Tron

# pip install tronapi hashlib
def query_tron_balance(private_key, trc20_contract=None):
    # 生成地址
    tron = Tron()
    address = tron.address.from_private_key(private_key)
    
    # 获取TRX余额
    trx_balance = get_trx_balance(address)
    
    # 获取TRC20代币余额（如USDT）
    token_balance = None
    if trc20_contract:
        token_balance = get_trc20_balance(address, trc20_contract)
    
    return {
        "address": address,
        "trx_balance": trx_balance,
        "token_balance": token_balance
    }

# 示例调用
result = query_tron_balance(
    private_key="你的私钥",
    trc20_contract="TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"  # USDT合约地址
)
print(result)
